﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using PPI.Data.Inspection;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;

namespace PPI.ServiceLogic.Distribution
{
    public class LDistributionResultType : IMobileTable
    {
        public static DataSet SelectAllIdName(string connectionKey)
        {
            return DInspectionResultType.SelectAllIdName(connectionKey);
        }

        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            listQueries.Add(new EMobileQuery(string.Format("DELETE tb_Lookups WHERE LookupTypeFk = '{0}'", "ResultType")));

            EMobileQuery insertQuery = new EMobileQuery("INSERT INTO tb_Lookups (LookupValue, LookupText, LookupTypeFk) VALUES (@id, @Name, 'ResultType')");
            
            //ResultType
            DataTable dt = SelectAllIdName(connectionKey).Tables[0];
            
            foreach (DataRow dr in dt.Rows)
            {
                List<SqlParameter> parameters = new List<SqlParameter>();

                parameters.Add(DBHelper.CreateIntParameter("@id", ParameterDirection.Input, false, Convert.ToInt32(dr["Vendor_InspVisit_XmissionStructures_ResultTypeId"])));
                parameters.Add(DBHelper.CreateNVarCharParameter("@Name", 100, ParameterDirection.Input, false, dr["Name"]));

                insertQuery.Parameters.Add(parameters);
            }

            listQueries.Add(insertQuery);

            return listQueries;
        }
    }
}
